home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ASME's Mechanical Engine…ing Toolkit 1997 December
/
ASME's Mechanical Engineering Toolkit 1997 December.iso
/
c_lang
/
varinc.lzh
/
PAGE78.C
< prev
next >
Wrap
C/C++ Source or Header
|
1979-11-30
|
2KB
|
40 lines
/* TO COMPILE FOR DEBUG: MSC LINELEN.C /DDEBUG /DDBGMAIN; */
/*****************************************************************************/
/* linelen() is the line-length function. It returns the number of */
/* characters before '\n' in the line, or -1 if '\0' is found before '\n'. */
/*****************************************************************************/
int linelen(line)
char line[]; /* the string to be processed */
{
short len;
for (len = 0; line[len] != '\0' && line[len] != '\n'; ++len)
#if defined(DEBUG)
printf("\nDEBUG: line[%d] = %c (hex: %x)\n",
len, line[len], line[len]); /* DEBUG output */
#else
; /* no DEBUG; a null loop body */
#endif
return (line[len] == '\n' ? len : -1); /* Returns -1 if '\0' before '\n'.*/
}
#if defined(DBGMAIN)
#define TESTFOR(cond, msg) if (!(cond)) \
printf("\7\n***TEST FAILED: %s\n", (msg))
/**************************************************************************/
/* Test driver to test the linelen() function. */
/**************************************************************************/
main()
{
TESTFOR(linelen("12\n") == 2, "linelen #1");
TESTFOR(linelen("\n") == 0, "linelen #2");
TESTFOR(linelen("") == -1, "linelen #3");
printf("linelen tests complete\n");
}
#endif